package io.geekidea.springbootplus.system.service.impl;

import io.geekidea.springbootplus.system.entity.ParcelCenter;
import io.geekidea.springbootplus.system.mapper.ParcelCenterMapper;
import io.geekidea.springbootplus.system.service.ParcelCenterService;
import io.geekidea.springbootplus.system.param.ParcelCenterPageParam;
import io.geekidea.springbootplus.system.vo.ParcelCenterQueryVo;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.Serializable;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
/**
 *  服务实现类
 *
 * @author miko
 * @since 2020-10-24
 */
@Slf4j
@Service
public class ParcelCenterServiceImpl extends BaseServiceImpl<ParcelCenterMapper, ParcelCenter> implements ParcelCenterService {

    @Autowired
    private ParcelCenterMapper parcelCenterMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveParcelCenter(ParcelCenter parcelCenter) throws Exception {
        return super.save(parcelCenter);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateParcelCenter(ParcelCenter parcelCenter) throws Exception {
        return super.updateById(parcelCenter);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteParcelCenter(Long id) throws Exception {
        return super.removeById(id);
    }


    @Override
    public List<ParcelCenter> getAllList(LambdaQueryWrapper<ParcelCenter> wrapper) throws Exception{
        return parcelCenterMapper.selectList(wrapper);
    }



    @Override
    public ParcelCenterQueryVo getParcelCenterById(Serializable id) throws Exception {
    return parcelCenterMapper.getParcelCenterById(id);
    }

    @Override
    public Paging<ParcelCenterQueryVo> getParcelCenterPageList(ParcelCenterPageParam parcelCenterPageParam) throws Exception {
        Page<ParcelCenterQueryVo> page = new PageInfo<>(parcelCenterPageParam, OrderItem.desc(getLambdaColumn(ParcelCenter::getCreateTime)));
        IPage<ParcelCenterQueryVo> iPage = parcelCenterMapper.getParcelCenterPageList(page, parcelCenterPageParam);
        return new Paging<ParcelCenterQueryVo>(iPage);
    }

}
